<template>
  <div class="antv-chart-mini">
    <div class="chart-wrapper" :style="{ height: 46 }">
      <v-chart :force-fit="true" :height="height" :data="dataChart" :scale="scale" :padding="[36, 5, 18, 5]">
        <v-tooltip />
        <v-bar position="x*y" />
      </v-chart>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
// const beginDay = new Date().getTime()

const tooltip = [
  'x*y',
  (x, y) => ({
    name: x,
    value: y
  })
]

const scale = [{
  dataKey: 'x',
}, {
  dataKey: 'y',
  alias: '笔数',
}]

export default {
  props: {
    dataList: {
      type: Array,
      default () {
        return []
      }
    }
  },
  name: 'MiniBar',
  data () {
    return {
      dataChart: [],
      tooltip,
      scale,
      height: 100
    }
  },
  created () {
    this.dataChart = []
    for (let i = 0; i < this.dataList.length; i++) {
      this.dataChart.push({
        x: moment(new Date(this.dataList[i].gmtCreate)).format('YYYY-MM-DD'),
        y: this.dataList[i].allNum
      })
    }
  }
}
</script>

<style lang="less" scoped>
  @import "chart";
</style>
